function showLanguage(event) {
    var lanInfo = document.getElementById("drop-menu");
    var style = window.getComputedStyle(lanInfo, null);
    var lanShow = document.getElementById("change-lan");
    if (style.display == "none") {
        lanInfo.style.display = "block";
        lanShow.style.textDecoration = "none";
    } else {
        lanInfo.style.display = "none";
        lanShow.style.textDecoration = "underline";
    }
    event.stopPropagation();
}

function hideLanguage() {
    var lanInfo = document.getElementById("drop-menu");
    var style = window.getComputedStyle(lanInfo, null);
    if (style.display == "block") {
        lanInfo.style.display = "none";
    }
}

function changeLan(event) {
    var chooseLan = event.target;
    var showLan = document.getElementById("change-lan").getElementsByTagName("span");
    var lanInfo = document.getElementById("drop-menu");
    var mLan = showLan[0].innerHTML;
    showLan[0].innerHTML = chooseLan.innerHTML;
    chooseLan.innerHTML = mLan;
    lanInfo.style.display = "none";
}

function showPrompt() {
    var info = document.getElementsByClassName("prompt-info");
    var acInfo = document.getElementById("account-info");
    var style = window.getComputedStyle(acInfo, null);
    if (style.display == "block") {
        info[0].style.display = "none";
    } else {
        info[0].style.display = "block";
    }
}

function hidePrompt() {
    var info = document.getElementsByClassName("prompt-info");
    info[0].style.display = "none";
}

function showAccount(event) {
    var acInfo = document.getElementById("account-info");
    var style = window.getComputedStyle(acInfo, null);
    var proInfo = document.getElementById("pro-info");
    if (style.display == "none") {
        acInfo.style.display = "block";
        proInfo.style.display = "none";
    } else {
        acInfo.style.display = "none";
        proInfo.style.display = "none";
    }
    event.stopPropagation();
}

function hideAccount() {
    var acInfo = document.getElementById("account-info");
    acInfo.style.display = "none";
}

function showTwPrompt(event) {
    var cover = document.getElementById("cover-info");
    var body = document.getElementsByTagName("body");
    var clientHeight = document.body.clientHeight;
    var clientWidth = document.body.client
    body[0].style.overflow = "hidden";
    cover.style.display = "block";
    if (event.currentTarget.className == "push-info") {
        var prompt = document.getElementById("twitter-prompt");
        prompt.style.display = "inline-block";
    } else if (event.currentTarget.className == "acinfo") {
        var prompt = document.getElementById("shortcut-prompt");
        prompt.style.display = "inline-block";
    } else if (event.currentTarget.className == "one-user") {
        var prompt = document.getElementById("one-tw-user");
        prompt.style.display = "inline-block";
    }
    var divHeight = prompt.offsetHeight;
    if (divHeight > clientHeight) {
        cover.style.height = divHeight + 100 + "px";
        var wrap = document.getElementById("wrap");
        wrap.className = "change-position";
        body[0].style.overflow = "visible";
    }
    event.stopPropagation();
}

function hideTwPrompt(num) {
    var cover = document.getElementById("cover-info");
    var body = document.getElementsByTagName("body");
    body[0].style.overflow = "visible";
    cover.style.display = "none";
    if (num == 1) {
        var prompt = document.getElementById("twitter-prompt");
        var text = document.getElementById("input-content");
        text.value = '';
        // window.clearInterval(timer);
        prompt.style.display = "none";
    } else if (num == 2) {
        var prompt = document.getElementById("shortcut-prompt");
        prompt.style.display = "none";
    } else if (num == 3) {
        var prompt = document.getElementById("one-tw-user");
        prompt.style.display = "none";
        var wrap = document.getElementById("wrap");
        wrap.className = "wrap-original";
    }
}

var flag = 1;

function picChange() {
    var picture = document.getElementById("bg-pic");
    setTimeout('fadeOutPic(' + 0.05 + ')', 5000);
}

function fadeOutPic(x) {
    var picture = document.getElementById("bg-pic");
    var style = window.getComputedStyle(picture, null);
    var opacity = style.opacity;
    if (opacity <= x) {
        picture.style.opacity = 0;
        setTimeout('fadeInPic(' + 0.05 + ')', 30);
    } else {
        opacity -= x;
        picture.style.opacity = opacity;
        setTimeout('fadeOutPic(' + x + ')', 30);
    }
}

function fadeInPic(x) {
    var picture = document.getElementById("bg-pic");
    var info = document.getElementsByClassName("tweet-info");
    var style = window.getComputedStyle(picture, null);
    var opacity = style.opacity;
    opacity = parseFloat(opacity);
    switch (flag) {
        case 1:
            picture.src = "image/bg2.jpg";
            info[flag - 1].className = "tweet-info";
            info[flag].className = "tweet-info active";
            break;
        case 2:
            picture.src = "image/bg3.jpg";
            info[flag - 1].className = "tweet-info";
            info[flag].className = "tweet-info active";
            break;
        case 3:
            picture.src = "image/bg4.jpg";
            info[flag - 1].className = "tweet-info";
            info[flag].className = "tweet-info active";
            break;
        case 4:
            picture.src = "image/bg5.jpg";
            info[flag - 1].className = "tweet-info";
            info[flag].className = "tweet-info active";
            break;
        case 5:
            picture.src = "image/bg6.jpg";
            info[flag - 1].className = "tweet-info";
            info[flag].className = "tweet-info active";
            break;
        case 6:
            picture.src = "image/bg1.jpg";
            info[flag - 1].className = "tweet-info";
            info[0].className = "tweet-info active";
    }
    if (opacity + x >= 1) {
        picture.style.opacity = 1;
        if (flag == 6) {
            flag = 1;
        } else {
            flag += 1;
        }
        setTimeout('fadeOutPic(' + 0.05 + ')', 5000);
    } else {
        opacity += x;
        picture.style.opacity = opacity;
        setTimeout('fadeInPic(' + x + ')', 30);
    }
}

var timer;

function countChar() {
    timer = setInterval(function() {
        var text = document.getElementById("input-content");
        var number = document.getElementById("number-char");
        var count = 140;
        var button = document.getElementsByClassName("special-button");
        var num = text.value.length;
        if (num > 0) {
            button[0].style.opacity = 1;
            count -= num;
            number.innerHTML = count;
        } else {
            button[0].style.opacity = 0.5;
            number.innerHTML = 140;
        }
        console.log(num);
    }, 100);
}

function cancelTimer() {
    window.clearInterval(timer);
}
